home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 March / CMCD0305.ISO / Software / Shareware / Programare / restuner / ResTuner_setup.exe / {app} / PLUGINS / SOURCE / DELPHI / t12dll.dpr < prev    next >
Text File  |  2005-01-11  |  8KB  |  215 lines

  1. //-----------------------------------------------------------------------------
  2. // PE Explorer Demo Plug-In
  3. // (c)2001 by Yuri Rai/Heaventools Software.
  4. // http://www.heaventools.com
  5. //
  6. // Pascal (Delphi):  t12dll.dpr
  7. //-----------------------------------------------------------------------------
  8.  
  9. library t12dll;
  10.  
  11. uses
  12.  Windows,
  13.  Messages;
  14.  
  15. {$R *.RES}
  16.  
  17. const
  18.  IName = 'PE Explorer Demo PlugIn';
  19.  
  20.  
  21. //-----------------------------------------------------------------------------
  22. // Prototype of function which allocates memory.  
  23. //
  24. // Used only to return results to PEX.
  25. // All other memory allocation should use standard library calls.
  26. //
  27. // Rather than being permanently loaded into memory, the plug-in uses this  
  28. // function at run-time, to request a buffer of the necessary size from PE 
  29. // Explorer where the plug-in can store the results of an operation. The 
  30. // plug-in does not need to clear the input buffer, or de-allocate the space 
  31. // after use, as these tasks are performed by PE Explorer.
  32. //
  33. // Input : Size - DWORD 
  34. //              - Size of requested memory
  35. // OutPut: Pointer
  36. //              - The pointer to allocated memory. In case of failure 
  37. //                when allocating memory returns nil.
  38.  type
  39.  PMemoryAllocator = ^TMemoryAllocator;
  40.  TMemoryAllocator = function (Size: DWORD): Pointer; stdcall;
  41.  
  42.  
  43. //-----------------------------------------------------------------------------
  44. // CallBack Events
  45. const
  46.  evID_PostLogInfo = 0;
  47.  
  48. // The prototype of the function, used by Plug-in to inform PEX of various 
  49. // events that have occurred at run time.
  50. //
  51. // IMPORTANT: Currently, only 'Post data to log' is supported.  
  52. //            For compatibility with future versions of PE Explorer, use  
  53. //            ONLY PREDEFINED EVENT TYPES.
  54. //
  55. // Input : None
  56. // Output: dwPGIID   - DWORD
  57. //              - Interface ID. It is used to uniquely specify a particular event  
  58. //                issued by the plug-in if several functions are executing at 
  59. //                the same time.
  60. //
  61. //                IMPORTANT: Only the Interface ID values received from PEX 
  62. //                           should be used.              
  63. //                 
  64. //         dwEventID - DWORD
  65. //              - Identifier of the occurred event.
  66. //
  67. //         pcMessage - Pointer
  68. //              - Pointer to the data that is necessary to transmit to PEX.
  69. //
  70. type
  71.  PPGICallBack = ^TPGICallBack;
  72.  TPGICallBack = procedure (dwPGIID: DWORD; dwEventID: DWORD; pcMessage: PChar); stdcall;
  73.  
  74.  
  75. //--------------------------------------------------------------------------------------
  76. // The structure by which interaction with PEX is achieved. 
  77. // ATTENTION! Under no circumstances should you modify the values marked as 
  78. //            Read Only! Changing these values may adversely affect the operation 
  79. //            of the program.            
  80. type
  81.  PPGIParamsBlock = ^TPGIParamsBlock;
  82.  TPGIParamsBlock = record
  83.   pMemAllocator       : PMemoryAllocator; // The address of the procedure
  84.                                           // allocating memory. The procedure
  85.                                           // is required for de-allocating
  86.                                           // memory correctly after use. 
  87.   pCallBack           : Pointer;          // Pointer to CallBack function.
  88.   pInBuff             : Pointer;          // Pointer to input buffer.
  89.   pOutBuff            : Pointer;          // Pointer to output buffer.
  90.                                           // Filled by plug-in if execution of  
  91.                                           // the function was successful.             
  92.                                                    
  93.   dwInSize            : DWORD;            // Size of input buffer.
  94.   dwOutSize           : DWORD;            // Size of output buffer.
  95.                                           // Filled by plug-in if execution of  
  96.                                           // the function was successful.
  97.   dwInterface         : DWORD;            // Interface ID. Read Only!
  98.   dwIndex             : DWORD;            // Index. (For internal use by PEX). 
  99.                                           // Read Only!
  100.  end;
  101.  
  102.  
  103.  
  104. //-----------------------------------------------------------------------------
  105. // The function executed prior to beginning data processing by PEX.
  106. // This function provides a generic means to perform any startup processing.
  107. // In the body of this function it is possible, for example, to place the code 
  108. // to unpack any packed files, and transmit them to PEX for further processing. 
  109. //
  110. // Input:  - the function receives PPGIParamsBlock and uses values sent to it.
  111. // Output: - returns True if execution was successful, otherwise it returns 
  112. //           False.
  113. //
  114. function PexPreloadImage(pPGIPB: PPGIParamsBlock): Boolean; stdcall;
  115. const
  116.  DemoMessage1 = 'Emulating Execution...';
  117.  DemoMessage2 = 'Allocating memory ...';
  118.  DemoMessage3 = 'Copy InBuff to OutBuff...';
  119.  DemoMessage4 = 'Runtime error: PexPreloadImage';
  120.  
  121. var MA : TMemoryAllocator;
  122.     CB : TPGICallBack;
  123. begin
  124.  // We have to return True if success and False in all 
  125.  // other cases (error occurred, haven't found data we can work with).
  126.  Result := False;
  127.  // Getting pointer to CallBack function
  128.  @CB := pPGIPB.pCallBack;
  129.  // Getting pointer to function that allocates memory
  130.  @MA := pPGIPB.pMemAllocator;
  131.  
  132.  // Emulating execution of the function
  133.  try
  134.   // Posting an event to the log.
  135.   if (@CB <> nil) then
  136.      CB(pPGIPB.dwInterface, evID_PostLogInfo, PChar(DemoMessage1));
  137.  
  138.   // Place your code here. For example, we will move input buffer to
  139.   // output buffer.
  140.   //
  141.   //***************************************************************************
  142.   // Posting an event to the log.
  143.   if (@CB <> nil) then
  144.      CB(pPGIPB.dwInterface, evID_PostLogInfo, PChar(DemoMessage2));
  145.  
  146.   // Asking PEX for allocating memory, and filling out the required fields
  147.   // in the structure. 
  148.   pPGIPB.pOutBuff  := MA(pPGIPB.dwInSize);
  149.   pPGIPB.dwOutSize := pPGIPB.dwInSize;
  150.  
  151.   // Moving data from one buffer to another.
  152.   System.Move(pPGIPB.pInBuff^, pPGIPB.pOutBuff^, pPGIPB.dwInSize);
  153.  
  154.   // Posting an event to the log.
  155.   if (@CB <> nil) then
  156.      CB(pPGIPB.dwInterface, evID_PostLogInfo, PChar(DemoMessage3));
  157.  
  158.   // Everything is OK
  159.   Result := True;
  160.   //***************************************************************************
  161.   //
  162.  except
  163.   // An error occurred while executing. Posting an event to the log.
  164.   if (@CB <> nil) then
  165.      CB(pPGIPB.dwInterface, evID_PostLogInfo, PChar(DemoMessage4));
  166.  end;
  167. end;
  168.  
  169.  
  170. //---------------------------------------------------------------------------
  171. // Optional procedure.
  172. //
  173. // If this procedure is present, PE Explorer adds an entry titled "Plug-ins - 
  174. // About <Name>"  to the menu.  The name is obtained by PE Explorer when the 
  175. // plug-in is registered.  This menu options allows infomormation about the 
  176. // plug-in to be displayed to the user.
  177. //
  178. procedure PexAboutPlugIn; Export; StdCall;
  179. var S : String;
  180. begin
  181.  // Place your code that displays 'About' info here.
  182.  // We are just showing MessageBox.
  183.  //***************************************************************************
  184.  S := IName + '.' + #$0D#$0A +'Version 1.0';
  185.  Windows.MessageBox(0, PChar(S), PChar('About'), MB_OK or MB_ICONINFORMATION);
  186. end;
  187.  
  188.  
  189. //---------------------------------------------------------------------------
  190. // The procedure called at Plug-in registration.
  191. //
  192. //  This should return to PE Explorer a pointer to the line, which contains the 
  193. //  plug-in name. PE Explorer uses this to associate the plug-in with any menu 
  194. //  items and events it provides.
  195. //
  196. //  IMPORTANT: The line should not be empty. The plug-in will not be registered 
  197. //             if an empty line is given.
  198. //
  199. procedure PexRegisterPlugIn(var N: PChar); Export; StdCall;
  200. begin
  201.  N := PChar(IName);
  202. end;
  203.  
  204.  
  205. //---------------------------------------------------------------------------
  206. exports
  207.   PexRegisterPlugIn   index 1,
  208.   PexAboutPlugIn      index 2,
  209.   PexPreloadImage     index 3;
  210. //---------------------------------------------------------------------------
  211.  
  212. begin
  213. end.
  214.  
  215.